/*
 * Curva.cpp
 *
 *  Created on: 23/04/2013
 *      Author: gonzalo
 */

#include "Curva.h"

Curva::Curva() {
	calculation_points = NULL;
	cant_points_allocated = 0;
}

Curva::~Curva() {
	if (calculation_points != NULL) {
		delete [] calculation_points;
	}
}

void Curva::set_control_points(glm::vec3 * points, GLuint n_points) {

	control_points.clear();

	//calculation_points.clear();

	for (uint i = 0; i < n_points; i++) {
		this->control_points.push_back(points[i].x);
		this->control_points.push_back(points[i].y);
		this->control_points.push_back(points[i].z);
	}

	if (n_points - 1 > cant_points_allocated) {
		cant_points_allocated = n_points - 1;
		if (calculation_points != NULL) {
			delete [] calculation_points;
		}
		calculation_points = new GLfloat[3 * (n_points - 1)];
	}

}

void Curva::add_control_point(glm::vec3 point) {
	this->control_points.push_back(point.x);
	this->control_points.push_back(point.y);
	this->control_points.push_back(point.z);

	if (this->control_points.size() - 3 > cant_points_allocated) {
		if (calculation_points != NULL) {
			delete [] calculation_points;
		}
		calculation_points = new GLfloat[3 * (this->control_points.size() - 1)];
	}
}

void Curva::clear_control_points() {
	control_points.clear();
}
